package com.yl.solution.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.yl.solution.entity.Resolved_Problem;
import com.yl.solution.model.RPModel;
import com.yl.solution.service.Resolved_ProblemService;
import com.yl.solution.service.impl.Resolved_ProblemServiceImpl;
import com.yl.solution.util.PaginationSupport;





@Controller
@RequestMapping("/RP")
public class Resolved_ProblemController {
	
	
	private Resolved_ProblemService service;
	private List<Resolved_Problem> listRP;
	private Integer pageNo;
	private PaginationSupport<Resolved_Problem> pageSupport;
	private RPModel RPModel;
	
	
	
	
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/selectList",method=RequestMethod.GET)
	public ModelAndView selectList(@RequestParam("name")String name,@RequestParam("type")int type){
		if(pageSupport == null)pageSupport = new PaginationSupport<Resolved_Problem>();
		Map map= new HashMap();
		String sketch = RPModel.getSketch();
		int question_type = RPModel.getQuestion_type_id();
		map.put("sketch", sketch);
		map.put("question_type", question_type);
		listRP = service.getResolved_ProblemByInfo(map, pageSupport.getCurrPageNo(), pageSupport.getPageSize());
		pageSupport.setItems(listRP);
		pageSupport.setTotalCount(service.getResolved_ProblemByCount(map));
		ModelAndView mav = new ModelAndView();
		mav.addObject("items", pageSupport.getItems());
		mav.setViewName("index");
		return mav;
	}
	
	
	@RequestMapping(value="/Login",method=RequestMethod.GET)
	public ModelAndView selectLogin(){
		if(pageSupport == null)pageSupport = new PaginationSupport<Resolved_Problem>();	
		listRP = service.getResolved_ProblemByInfo(null, pageSupport.getCurrPageNo(), pageSupport.getPageSize());
		pageSupport.setItems(listRP);
		pageSupport.setTotalCount(service.getResolved_ProblemByCount(null));
		ModelAndView mav = new ModelAndView();
		mav.addObject("items", pageSupport.getItems());
		mav.setViewName("index");
		return mav;
	}
	
	@RequestMapping(value="/seelctById",method=RequestMethod.GET)
	public ModelAndView selectById(@RequestParam("id")Integer id){
		listRP = service.selectById(id);
		ModelAndView mav = new ModelAndView();
		mav.addObject("list", listRP);
		mav.setViewName("detailed");
		return mav;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	@RequestMapping("/demo")
	public ModelAndView demo(){
		ModelAndView mv = new ModelAndView();
		mv.addObject("list",1);
		mv.setViewName("users");
		return mv;
	}
	
	
	
	
	
	public Resolved_ProblemService getService() {
		return service;
	}


	public void setService(Resolved_ProblemService service) {
		this.service = service;
	}


	public List<Resolved_Problem> getListRP() {
		return listRP;
	}


	public void setListRP(List<Resolved_Problem> listRP) {
		this.listRP = listRP;
	}


	public Integer getPageNo() {
		return pageNo;
	}


	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}


	public PaginationSupport<Resolved_Problem> getPageSupport() {
		return pageSupport;
	}


	public void setPageSupport(PaginationSupport<Resolved_Problem> pageSupport) {
		this.pageSupport = pageSupport;
	}


	public RPModel getRPModel() {
		return RPModel;
	}


	public void setRPModel(RPModel rPModel) {
		RPModel = rPModel;
	}
	
	
}
